package com.syqc.monitor.ui.carmonitor

import android.Manifest
import android.annotation.SuppressLint
import android.location.Location
import android.view.View
import android.widget.TextView
import androidx.core.text.HtmlCompat
import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import autodispose2.autoDispose
import com.amap.api.maps.AMap
import com.amap.api.maps.AMapUtils
import com.amap.api.maps.CameraUpdateFactory
import com.amap.api.maps.model.LatLng
import com.amap.api.maps.model.Marker
import com.google.gson.reflect.TypeToken
import com.permissionx.guolindev.PermissionX
import com.syqc.maps.utils.MapUtil
import com.syqc.adapter.CarInfoAdapter
import com.syqc.adapter.OperInfoAdapter
import com.syqc.base.BaseMapLocationFragment
import com.syqc.comlib.AppConfigs
import com.syqc.comlib.MenuKey
import com.syqc.comlib.UserConstant
import com.syqc.comlib.rx.LiveDataBus
import com.syqc.comlib.rx.filterFast
import com.syqc.comlib.utils.ActivityResultUtil.launchAct
import com.syqc.comlib.utils.ActivityResultUtil.registerResultOk
import com.syqc.comlib.utils.GsonUtil
import com.syqc.comlib.utils.startActivityTo
import com.syqc.comlib.utils.toast
import com.syqc.comlib.utils.toastLong
import com.syqc.login.FunKey
import com.syqc.login.FunType
import com.syqc.login.InfoSetModel
import com.syqc.login.LocationStatusModel
import com.syqc.maps.utils.MarkerSet
import com.syqc.maps.utils.NaviActivity
import com.syqc.monitor.R
import com.syqc.monitor.databinding.FragmentMapCar2Binding
import com.syqc.monitor.databinding.IncludeCarMapInfoBinding
import com.syqc.monitor.databinding.IncludeMapPlateTrafficBinding
import com.syqc.monitor.popup.DriversPopup
import com.syqc.monitor.popup.LegendPopup2
import com.syqc.monitor.ui.carinfo.CarInfoActivity
import com.syqc.monitor.ui.set.InfoSet2Activity
import com.syqc.monitor.ui.tyre.TyreInfoActivity
import com.syqc.monitor.utils.ActivityUtil
import com.syqc.utils.ColorUtil
import com.syqc.utils.DataUtil
import com.syqc.utils.Keys
import com.syqc.utils.ToolsUtil
import com.syqc.utils.Units
import com.syqc.videos.CarMonitorViewModel
import com.syqc.videos.TalkPopup
import com.syqc.videos.TalkStatus
import com.syqc.videos.TalkbackUtil
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import java.text.DecimalFormat

/** @Author Jasper @Time 2020/7/22 @Desc 车辆 地图监控 */
class CarMapFragment(private val isCarUser: Boolean = false) :
    BaseMapLocationFragment<FragmentMapCar2Binding>(FragmentMapCar2Binding::inflate) {
    //是否可见AppConfigs.isMapInfoOpen
    var isResume = false
    private var mMarker: Marker? = null
    private var mLatLng: LatLng? = null
    private var mLocationLatLng: LatLng? = null
    private lateinit var mTrafficVB: IncludeMapPlateTrafficBinding
    private lateinit var mInfoVB: IncludeCarMapInfoBinding
    private var mLocationMarker: Marker? = null

    //是否录音
    private var isRecord = true

    //是否定位
    private var isLocation = false

    //是否展示彈窗
    private var isShowPopup = true

    //是否移动
    private var isMove = true

    private val popupLegend: LegendPopup2 by lazy { LegendPopup2(requireContext()) }
    private val mViewModel: CarMapViewModel by viewModels()
    private val mActivityVM by activityViewModels<CarMonitorViewModel>()
    private val mDriversPopup by lazy { DriversPopup(requireContext()) }

    private val talkPopup by lazy {
        TalkPopup(requireContext()) {
            isRecord = true
            TalkbackUtil.closeTalk()
        }
    }


    override fun initView(view: View) {
        mTrafficVB = IncludeMapPlateTrafficBinding.bind(binding.root)
        mInfoVB = IncludeCarMapInfoBinding.bind(binding.root)
        mMap?.setInfoWindowAdapter(object : AMap.InfoWindowAdapter {
            override fun getInfoWindow(p0: Marker?): View? {
                return null
            }

            override fun getInfoContents(p0: Marker?): View? {
                return getInfoWindow()
            }
        })

        mMap?.setOnInfoWindowClickListener {
            mViewModel.gpsDetail?.run {
                startActivityTo<NaviActivity>(requireContext()) {
                    putExtra(Keys.INTENT_PLATE, carPlate)
                    putExtra("eLat", glat)
                    putExtra("eLng", glng)
                    putExtra("bLat", blat)
                    putExtra("bLng", blng)
                }
            }
        }

        mMap?.setOnMapClickListener {
            if (mLocationMarker?.isInfoWindowShown == true) {
                mLocationMarker!!.hideInfoWindow()
            }
        }

        mMap?.run {
            MapUtil.initMapSetting(this)
            setOnMarkerClickListener {
                if (it == mMarker) {
                    mMap?.mapScreenMarkers?.forEach { marker ->
                        if (marker != mMarker) marker.remove()
                    }
                    isShowPopup = true
                    isMove = true
                    mTrafficVB.tvCarCarShow.setText(R.string.desc_com_hide)
                    mInfoVB.llCarInfo.isVisible = true
                    MapUtil.showLatLngZoom(this, it.position)
                } else if (it == mLocationMarker) {
                    it.showInfoWindow()
                }
                return@setOnMarkerClickListener true
            }
            mapType = mViewModel.mMapType
            isTrafficEnabled = mViewModel.isCarTraffic

        }
        mTrafficVB.ivCarTraffic.isSelected = mViewModel.isCarTraffic
        if (mViewModel.mMapType == AMap.MAP_TYPE_NORMAL) {
            mTrafficVB.tvCarMapState.setText(R.string.desc_com_map_state_normal)
        } else {
            mTrafficVB.tvCarMapState.setText(R.string.desc_com_map_state_satellite)
        }
        setPlate()
        infoView()
        infoEvent()

        if (UserConstant.loginType == Keys.LOGIN_TYPE_CAR) {
            if (mViewModel.isShow) {
                mViewModel.isShow = false
            }
        }
    }


    override fun initData() {
        mActivityVM.carId.observe(this) {
            if (mMarker != null) {
                mInfoVB.llCarInfo.isVisible = false
                mMarker!!.remove()
                mMarker = null
            }
            mMap?.clear()
            mLocationMarker?.remove()
            mViewModel.carId = it
            isShowPopup = true
            isMove = true
            mTrafficVB.tvCarCarShow.setText(R.string.desc_com_hide)
            binding.rlRefresh.isVisible = true
            ToolsUtil.startAmin(binding.ivRefresh)
        }


        mViewModel.toastObserver()
            .observeOn(AndroidSchedulers.mainThread()).autoDispose(scopeProvider)
            .subscribe(this::toastObserver)

        mViewModel.locationSub.hide().autoDispose(scopeProvider).subscribe {
            it.run {
                if (glat.isEmpty() || glng.isEmpty()) return@run
                mLatLng = LatLng(glat.toDouble(), glng.toDouble())
                val bitmapDes =
                    MarkerSet.getBitmapDes(
                        requireContext(),
                        carId, state, drct, carName, carPlate, iconLink, mViewModel.isPlate, speed
                    )
                if (mMarker == null) {
                    mMarker = MapUtil.addAndGetMarker(mMap!!, mLatLng!!, bitmapDes)
                } else {
                    mMarker?.run {
                        position = mLatLng
                        setIcon(bitmapDes)
                    }
                }
                if (isShowPopup) {
                    mInfoVB.llCarInfo.isVisible = true
                    initInfo()
                }
                if (isMove) {
                    isMove = false
                    MapUtil.showLatLngZoom(mMap!!, mLatLng!!)
                } else if (AppConfigs.isCenter) {
                    MapUtil.showMapLatLng(mMap!!, mLatLng!!)
                }

                if (mLocationMarker?.isInfoWindowShown == true) {
                    viewHolder?.setRange()
                }
            }
        }
        mViewModel.legendSub.hide().autoDispose(scopeProvider).subscribe({
            popupLegend.showAtLocation(binding.ivCarCarLegend, it)
        }, {
            showToast(it.message ?: getString(R.string.toast_no_back_error_info))
        })
        //时间刷新监听
        mViewModel.timeObserver().observeOn(AndroidSchedulers.mainThread())
            .autoDispose(scopeProvider).subscribe {
                if (it == 1) {
                    ToolsUtil.stopAmin(binding.ivRefresh)
                    ToolsUtil.startAmin(binding.ivRefresh)
                }
                if (it / 3600 > 0) {
                    binding.tvRefreshTime.text = "${it / 60}${getString(R.string.unit_minute_)}"
                } else if (it / 60 > 0) {
                    binding.tvRefreshTime.text = "${it / 60}${getString(R.string.unit_minute_)}"
                } else {
                    binding.tvRefreshTime.text = "${it}${getString(R.string.unit_second_)}"
                }
            }
    }


    override fun initEvent() {
        mTrafficVB.tvCarMapState.filterFast {
            if (mViewModel.mMapType == AMap.MAP_TYPE_NORMAL) {
                mViewModel.mMapType = AMap.MAP_TYPE_SATELLITE
                mMap?.mapType = AMap.MAP_TYPE_SATELLITE
                mTrafficVB.tvCarMapState.setText(R.string.desc_com_map_state_satellite)
            } else {
                mViewModel.mMapType = AMap.MAP_TYPE_NORMAL
                mMap?.mapType = AMap.MAP_TYPE_NORMAL
                mTrafficVB.tvCarMapState.setText(R.string.desc_com_map_state_normal)
            }
        }
        mTrafficVB.tvCarCarState.filterFast {
            mViewModel.isPlate = !mViewModel.isPlate
            setPlate()
            mViewModel.refresh()
        }

        mTrafficVB.ivCarTraffic.filterFast {
            mViewModel.isCarTraffic = !mViewModel.isCarTraffic
            mTrafficVB.ivCarTraffic.isSelected = mViewModel.isCarTraffic
            mMap?.isTrafficEnabled = mViewModel.isCarTraffic

        }

        binding.ivCarLocation.filterFast {
            isLocation = true
            getPermissions(false)
        }

        binding.ivCarCarLocation.filterFast {
            if (mLatLng == null) {
                showToast(R.string.hint_toast_choose_car)
            } else {
                isShowPopup = true
                mTrafficVB.tvCarCarShow.setText(R.string.desc_com_hide)
                mInfoVB.llCarInfo.isVisible = true
                MapUtil.showLatLngZoom(mMap!!, mLatLng!!)
            }

        }

        binding.ivCarCarLegend.filterFast {
            mViewModel.getLegend(mViewModel.carId)
        }

        mTrafficVB.tvCarCarShow.filterFast {
            if (mViewModel.carId.isNullOrEmpty()) {
                showToast(R.string.hint_toast_choose_car)
                return@filterFast
            }
            if (mViewModel.gpsDetail == null) {
                showToast(R.string.toast_no_location_msg)
                return@filterFast
            }
            if (isShowPopup) {
                isShowPopup = false
                mTrafficVB.tvCarCarShow.setText(R.string.desc_com_display)
                mInfoVB.llCarInfo.isVisible = false
            } else {
                isShowPopup = true
                mTrafficVB.tvCarCarShow.setText(R.string.desc_com_hide)
                mInfoVB.llCarInfo.isVisible = true
            }
        }

        //放大
        binding.ivMapZoomIn.setOnClickListener {
            mMap?.animateCamera(CameraUpdateFactory.zoomOut(), 600, null)
        }

        //缩小
        binding.ivMapZoomOut.setOnClickListener {
            mMap?.animateCamera(CameraUpdateFactory.zoomIn(), 600, null)
        }
    }

    private fun setPlate() {
        if (mViewModel.isPlate) {
            mTrafficVB.tvCarCarState.setText(R.string.desc_car_plate)
        } else {
            mTrafficVB.tvCarCarState.setText(R.string.desc_car_name)
        }
    }

    /////////////////////////////////  popupView ///////////////////////////////////////////////////
    private var popupView: View? = null
    private var viewHolder: ViewHolder? = null

    private inner class ViewHolder(view: View) {
        private val df = DecimalFormat("#.0")
        private val tvRangeDesc: TextView = view.findViewById(R.id.tvRangeDesc)
        private val desc = getString(R.string.desc_location_now)

        fun setRange() {
            val range = AMapUtils.calculateLineDistance(mLatLng, mLocationLatLng)
            val value = if (range > 1000) {
                df.format(range / 1000)
            } else {
                range.toString().split(".")[0]
            }
            val unit = if (range > 1000) Units.km else Units.m
            val htmlStr =
                "<font color='#111111'>$desc</font><font color='#2D94F1'>$value</font> <font color='#111111'>$unit</font>"
            val html = HtmlCompat.fromHtml(htmlStr, HtmlCompat.FROM_HTML_MODE_LEGACY)
            tvRangeDesc.text = html
        }
    }

    private fun getInfoWindow(): View {
        viewHolder =
            if (popupView == null) {
                popupView = View.inflate(requireContext(), R.layout.popup_location, null)
                val holder = ViewHolder(popupView!!)
                popupView!!.tag = holder
                holder
            } else {
                popupView!!.tag as ViewHolder
            }

        viewHolder!!.setRange()
        return popupView!!
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////
    //是否隐藏状态变化监听
    override fun onHiddenChanged(hidden: Boolean) {
        super.onHiddenChanged(hidden)
        if (hidden) {
            mViewModel.stopTime()
            ToolsUtil.stopAmin(binding.ivRefresh)
            mViewModel.isHidden = true
        } else {
            if (isResume) hidden()
        }
    }

    override fun onResume() {
        super.onResume()
        if (isResume) hidden()
    }

    private fun hidden() {
        if (!mViewModel.isHidden) return
        mViewModel.isHidden = false
        val data = if (isCarUser) {
            InfoSetModel.getCarInfo()
        } else {
            InfoSetModel.getChooseList(FunType.CAR_MAP)
        }
        operInfoAdapter.setList(data)
        mViewModel.carId?.let {
            mViewModel.startTime(it)
            ToolsUtil.startAmin(binding.ivRefresh)
            binding.rlRefresh.isVisible = true
        }
    }

    override fun onPause() {
        super.onPause()
        mViewModel.stopTime()
        ToolsUtil.stopAmin(binding.ivRefresh)
        binding.rlRefresh.isVisible = false
        mViewModel.isHidden = true
    }

    override fun onDestroy() {
        mMap?.setInfoWindowAdapter(null)
        MarkerSet.recycleLruCache()
        TalkbackUtil.destroy()
        super.onDestroy()
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////
    private val runSpeed by lazy { getString(R.string.desc_run_speed) }
    private val dayMile by lazy { getString(R.string.desc_day_mile) }

    @SuppressLint("SetTextI18n")
    fun initInfo() {
        mViewModel.gpsDetail?.run {
            mInfoVB.tvCarRunSpeed.text = "$speed ${Units.speed}\n$runSpeed"
            mInfoVB.tvCarRunStop.text = runStopTime
            mInfoVB.tvCarDayMile.text = "$preMile ${Units.km}\n$dayMile"
            mInfoVB.tvCarTotalMile.text = "$mile ${Units.km}"
            mInfoVB.tvCarTime.text = "${getString(R.string.desc_location_time)}：$time"
            mInfoVB.tvSatl.text = "${getString(R.string.desc_marker_loaction)}${satl.split("-")[0]}"
            mInfoVB.tvSgn.text = "${getString(R.string.desc_marker_sgn)}${sgn.split("-")[0]}"
            ColorUtil.lineState(mInfoVB.tvOnLine, state)

            val title = if (mViewModel.isPlate) carPlate else carName
            ColorUtil.setPlateColor(
                mInfoVB.tvPlateArea,
                mInfoVB.tvPlateNum,
                plateColor,
                plateColorCode,
                title
            )
            val isTalk = mViewModel.talkChannel.isNotEmpty()
            if (isTalk != operInfoAdapter.isCanTalk)
                operInfoAdapter.isCanTalk = isTalk
        }
        if (isShowRecycler) {
            showInfoRecycler()
        }
    }


    private val mInfoAdapter by lazy { CarInfoAdapter() }
    private fun infoView() {
        mInfoVB.recyclerCarInfo.layoutManager = LinearLayoutManager(requireContext())
        mInfoVB.recyclerCarInfo.adapter = mInfoAdapter

        handleOper()
    }

    private fun showInfoRecycler() {
        mInfoAdapter.setList(LocationStatusModel.upData(mViewModel.gpsDetail))
    }

    //是否展示列表
    private var isShowRecycler = AppConfigs.isMapInfoOpen

    /** 设置info点击事件 */
    private fun infoEvent() {
        LiveDataBus.get().with("upInfoState").observe(this) {
            if (mViewModel.carId.isNullOrEmpty()) return@observe
            mViewModel.refresh()
        }
        mInfoVB.ivTyre.isVisible = UserConstant.current_ip != "113.105.152.93"
        if (isShowRecycler) {
            showInfoRecycler()
            mInfoVB.recyclerCarInfo.isVisible = true
        } else {
            mInfoVB.recyclerCarInfo.isVisible = false
        }
        mInfoVB.ivUpDown.isSelected = isShowRecycler
        if (isShowRecycler) {
            showInfoRecycler()
            mInfoVB.recyclerCarInfo.isVisible = true
        } else {
            mInfoVB.recyclerCarInfo.isVisible = false
        }
        mInfoVB.ivUpDown.setOnClickListener {
            isShowRecycler = !isShowRecycler
            mInfoVB.ivUpDown.isSelected = isShowRecycler
            if (isShowRecycler) {
                showInfoRecycler()
                mInfoVB.recyclerCarInfo.isVisible = true
            } else {
                mInfoVB.recyclerCarInfo.isVisible = false
            }
        }

        mInfoVB.ivCarSet.setOnClickListener {
            if (ToolsUtil.isFastClick()) return@setOnClickListener
            startActivityTo<InfoSet2Activity>(requireContext())
        }

        mInfoVB.ivCarClose.setOnClickListener {
            isShowPopup = false
            mTrafficVB.tvCarCarShow.setText(R.string.desc_com_display)
            mInfoVB.llCarInfo.isVisible = false
        }

        mInfoVB.ivCarRefresh.setOnClickListener {
            if (ToolsUtil.isFastClick()) return@setOnClickListener
            mViewModel.refresh2()
        }


        mInfoVB.ivTyre.setOnClickListener {
            mViewModel.gpsDetail?.let {
                val list = LocationStatusModel.getExtsValue(it.exts, "c8")
                if (list.isEmpty()) {
                    showToast(R.string.desc_toast_no_data_tyre)
                    return@setOnClickListener
                }
                val type = object : TypeToken<List<List<String>>>() {}
                val data: List<List<String>> = GsonUtil.gson.fromJson(list, type.type)
                DataUtil.psiTyres = data
                startActivityTo<TyreInfoActivity>(requireActivity()) {
                    putExtra(Keys.INTENT_TITLE, if (mViewModel.isPlate) it.carPlate else it.carName)
                }
            }
        }
    }


    private val launcher = registerResultOk { result ->
        mViewModel.isHidden = false
        mViewModel.carId?.let {
            mViewModel.startTime(it)
            ToolsUtil.startAmin(binding.ivRefresh)
            binding.rlRefresh.isVisible = true
        }
    }


    /** 定位变化监听事件 */
    override fun onMyLocationChange(location: Location) {
        if (location.extras == null) return

        val bundle = location.extras!!["errorCode"] ?: return
        if (bundle != 0) {
            bundle.toastLong(requireContext())
            return
        }
        mLocationLatLng = LatLng(location.latitude, location.longitude)
        if (isLocation) mLocationLatLng?.run {
            isShowPopup = false
            mInfoVB.llCarInfo.isVisible = false
            mTrafficVB.tvCarCarShow.setText(R.string.desc_com_display)
            if (mLatLng == null) {
                MapUtil.showMapLatLng(mMap!!, this)
            } else {
                MapUtil.showMapBounds(
                    mMap!!,
                    mViewModel.setBounds(mLatLng!!, this),
                    300
                )
            }
            mLocationMarker = MapUtil.addAndGetMarker(
                mMap!!, this, R.mipmap.ic_phone_location
            )
            mLocationMarker!!.showInfoWindow()
            return
        }
    }

    private val operInfoAdapter by lazy { OperInfoAdapter(FunType.CAR_MAP) }

    private fun handleOper() {
        mInfoVB.rvType.layoutManager = GridLayoutManager(requireContext(), 6)
        mInfoVB.rvType.adapter = operInfoAdapter
        val data = if (isCarUser) {
            InfoSetModel.getCarInfo()
        } else {
            InfoSetModel.getChooseList(FunType.CAR_MAP)
        }
        operInfoAdapter.setList(data)
        operInfoAdapter.setOnItemClickListener { adapter, view, position ->
            val info = operInfoAdapter.data[position]
            if (!info.isCheckable) {
                R.string.toast_check_other_menu.toast(requireContext())
                return@setOnItemClickListener
            }
            when (info.key) {
                FunKey.FUN_Talk -> {
                    if (!operInfoAdapter.isCanTalk) {
                        R.string.toast_no_channel.toast(requireContext())
                        return@setOnItemClickListener
                    }
                    getAudioPermissions()
                }

                MenuKey.MENU_916 -> {
                    mViewModel.stopTime()
                    mViewModel.isHidden = true
                    launcher.launchAct<CarInfoActivity>(requireContext()) {
                        putExtra(Keys.INTENT_CAR_ID, mViewModel.carId)
                    }
                }

                FunKey.FUN_NAVI -> {
                    isLocation = false

                    mViewModel.gpsDetail?.run {
                        startActivityTo<NaviActivity>(requireContext()) {
                            putExtra(Keys.INTENT_PLATE, carPlate)
                            putExtra("eLat", glat)
                            putExtra("eLng", glng)
                            putExtra("bLat", blat)
                            putExtra("bLng", blng)
                        }
                    }

                }

                FunKey.FUN_CALL -> {
                    if (mViewModel.driverInfo.isNotEmpty()) {
                        if (mViewModel.driverInfo.size == 1) {
                            ToolsUtil.talkPhone(
                                requireContext(),
                                mViewModel.driverInfo[0].driverPhone
                            )
                        } else {
                            mDriversPopup.show(
                                requireActivity().window.decorView,
                                mViewModel.driverInfo
                            )
                        }
                    } else {
                        R.string.desc_no_phone.toast(requireContext())
                    }
                }

                else -> {
                    InfoSetModel.startFunActivity(
                        requireActivity(),
                        ActivityUtil.getActivityByKey(info.key),
                        mViewModel.gpsDetail
                    )
                }
            }
        }

        TalkbackUtil.statusMap.autoDispose(scopeProvider).subscribe {
            when (it) {
                TalkStatus.CLOSE -> {
                    talkPopup.setVoiceTitle(R.string.toast_audio_close)
                    talkPopup.dismiss()
                }

                TalkStatus.OPEN -> {
                    talkPopup.shouPopup(requireView())
                    talkPopup.setVoiceTitle(R.string.toast_audio_link)
                }

                TalkStatus.SUCCESS -> {
                    talkPopup.setVoiceTitle(R.string.toast_audio_talking)
                }

                TalkStatus.FAILURE -> {
                    talkPopup.setVoiceTitle(TalkbackUtil.toast)
                    mInfoVB.rvType.postDelayed({
                        talkPopup.dismiss()
                    }, 3000)
                }

                else -> {}
            }
        }
        //上传PCM数据网络失败监听
        TalkbackUtil.uploadMap.autoDispose(scopeProvider).subscribe {
            isRecord = true
            TalkbackUtil.closeTalk()
            talkPopup.dismiss()
        }
        TalkbackUtil.imageMap.autoDispose(scopeProvider).subscribe {
            talkPopup.setVoiceImage(it)
        }
        TalkbackUtil.toastLive.observeOn(AndroidSchedulers.mainThread()).autoDispose(scopeProvider)
            .subscribe {
                showToast(it)
            }
    }


    private fun getAudioPermissions() {
        PermissionX.init(requireActivity()).permissions(
            Manifest.permission.RECORD_AUDIO
        ).request { allGranted, grantedList, deniedList ->
            if (allGranted) {
                isRecord = false
                TalkbackUtil.openTalk(
                    requireContext(), mViewModel.carId!!, mViewModel.talkChannel, true
                )
            } else {
                getString(
                    R.string.toast_persission_open,
                    getString(R.string.permission_audio)
                ).toast(requireContext())
            }
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        DataUtil.psiTyres = null
    }
}